﻿using System;

namespace Remote_Server
{
    class ResponceClass
    {
        private string Msg = "";
        private string MsgReturn = "";
        private string[] Parameters;
        private StateEnum sState;
        private static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
        
        public void MakeResponce(string IncommingString)
        {
            try
            {
                Msg = IncommingString;
                Parameters = Msg.Split(' ');
                
                string CommandName = Parameters[0];

                 if (CommandName == "STATUS")
                {
                    MsgReturn = GetStatusMessage();
                    return;
                }

                if (CommandName == "SHUTDOWN")
                {
                    MsgReturn = ShutdownServer();
                    return;
                }

                ReturnDefaultError();
            }

            catch (Exception e)
            {
                log.Error("Error in MakeResponce: " + e.Message);
                sState = StateEnum.OtherError;
                MsgReturn = e.Message;
                return;
            }
        }

        #region "Private Methods"


        private string GetStatusMessage()
        {
            return Client.GetStatus();
        }

        private string ShutdownServer()
        {
            throw new NotImplementedException();
        }

        private void ReturnDefaultError()
        {
            log.Error("The command string was wrong: " + Msg);
            MsgReturn = "Error: Command not found";
        }

        #endregion

        #region "Public Properties"

        public string ReturnMsg
        {
            get { return MsgReturn; }
        }

        public StateEnum ResponceState
        {
            get { return sState; }
        }
        public enum StateEnum
        {
            Success = 1,
            WrongCommand = 2,
            DecryptionError = 3,
            OtherError = 4

        }

        #endregion

    }
}